﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SuYuanRabbit.Infrastructure.Interfaces
{
    /// <summary>
    /// 基础仓储接口
    /// </summary>
    public interface IBaseRepository<T> where T : class
    {
        /// <summary>
        /// 根据Id获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回对象</returns>
        Task<T> GetByIdAsync(object id);
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns>返回集合</returns>
        Task<IEnumerable<T>> GetAll();
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>返回受影响行数</returns>
        Task AddAsync(T entity);
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>返回受影响行数</returns>
        Task UpdateAsync(T entity);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回受影响行数</returns>
        Task DeleteAsync(object id);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="predicate">表达式树</param>
        /// <returns>集合</returns>
        Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate);
    }
}
